package com.example.shoppingdemo.Center;


import android.content.Context;
import android.graphics.Color;
import android.util.Size;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.shoppingdemo.R;

import java.util.List;

public class LeftAdapter extends RecyclerView.Adapter<LeftAdapter.LeftHolder>{
    private Context context;

    private List<LeftModel> leftData;

    private onLeftItemClickListener listener;

    public LeftAdapter(Context context) {
        this.context = context;
    }

    public void setLeftData(List<LeftModel> leftData) {
        this.leftData = leftData;
    }

    public void setListener(onLeftItemClickListener listener) {
        this.listener = listener;
    }

    @NonNull
    @Override
    public LeftHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        LeftHolder holder=new LeftHolder(LayoutInflater.from(context).inflate(R.layout.center_list_item,null));
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null !=listener){
                    listener.onLeftItemClick(holder.getAdapterPosition());
                }
            }
        });
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull LeftHolder holder, int position) {
        holder.leftItem.setText(leftData.get(position).getName());
        if (leftData.get(position).isSelect()){
            holder.leftItem.setTextColor(Color.parseColor("#F37028"));
            holder.leftItem.setTextSize(16);
        }else {
            holder.leftItem.setTextSize(16);
            holder.leftItem.setTextColor(Color.parseColor("#464444"));
        }
    }

    @Override
    public int getItemCount() {
        return null == leftData ? 0:leftData.size();
    }

    public void setRightData(List<RightModel> rightData) {
    }


    class LeftHolder extends RecyclerView.ViewHolder
    {

        TextView leftItem;

        public LeftHolder(@NonNull View itemView)
        {
            super(itemView);
            leftItem =
                    itemView.findViewById(R.id.list_item);
        }
    }

  public interface onLeftItemClickListener
    {

        void onLeftItemClick(int position);
    }

}
